package com.mf.ergate.web.controller;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 系统异常控制器
 * User: zhaoming
 * DateTime: 2017-11-06
 * To change this template use File | Settings | File Templates.
 */
@Controller
public class ErrorHandlerController implements ErrorController {

    @RequestMapping(value="/error")
    public ModelAndView getErrorPath(HttpServletRequest request, HttpServletResponse response){
        ModelAndView modelAndView = new ModelAndView();
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        switch (statusCode) {
            case 404:
                modelAndView.setViewName("common/error/public_error_404");
                break;
            case 500:
                modelAndView.setViewName("common/error/public_error_500");
                break;
            default:
                modelAndView.setViewName("common/error/public_error_500");
                break;
        }
        return modelAndView;
    }

    @Override
    public String getErrorPath() {
        return "/common/error";
    }
}
